import { bind } from "../../core/module/proxy/ProxyDecorator";
import { UIBase } from "../../core/module/ui/UIBase";
import { ToastAlertProxy } from "../../script/proxy/ToastAlertProxy";
@bind(ToastAlertProxy)
export class ToastAlert extends UIBase<ToastAlertProxy> {
    private _alertCallback: (isSure: boolean) => void = null;
    onInit(): void {
        this._view.btnOk.onClick(this, this.onAlertSureClick);
        this._view.btnCancel.onClick(this, this.onAlertCancelClick);
    }

    onShow(): void {
        super.onShow();
        this._view.msg.string = this.args.msg;
        this._alertCallback = this.args.callback;
        this._view.c1 = this.args.showCancel ? 1 : 0;
    }

    /**
     * 确认点击
     */
    public onAlertSureClick() {
        this.onClose();
        if (this._alertCallback) {
            this._alertCallback(true);
        }
    }

    /**
     * 关闭点击
     */
    public onAlertCancelClick() {
        this.onClose();
        if (this._alertCallback) {
            this._alertCallback(false);
        }
    }
}